import { request, downloadFile } from '/@/utils/service';
import { UserPageQuery } from '@fast-crud/fast-crud';

export const apiPrefix = '/api/supplier_product/';

export interface ExtendedPageQuery extends UserPageQuery {
    ordering?: string;
}

export function GetList(query: ExtendedPageQuery) {
    return request({
        url: apiPrefix,
        method: 'get',
        params: query
    });
}

export function AddObj(obj: any) {
    return request({
        url: apiPrefix,
        method: 'post',
        data: obj
    });
}

export function UpdateObj(obj: any) {
    return request({
        url: apiPrefix + obj.id + '/',
        method: 'put',
        data: obj
    });
}

export function DelObj(id: string) {
    return request({
        url: apiPrefix + id + '/',
        method: 'delete',
        data: { id }
    });
}

export function GetObj(id: string) {
    return request({
        url: apiPrefix + id + '/',
        method: 'get'
    });
}

export function exportData(params: any) {
    return downloadFile({
        url: apiPrefix + 'export_data/',
        params: params,
        method: 'get'
    });
}

export function getSupplierProducts(supplierId: string) {
    return request({
        url: `/api/supplier/${supplierId}/products/`,
        method: 'get'
    });
} 